package com.donn.securitycontrolplatform.alarm.service;

import com.donn.securitycontrolplatform.common.Result;
import com.donn.securitycontrolplatform.db1.mapper.TAlarmConfigMapper;
import com.donn.securitycontrolplatform.rpmClient.TcpClient;
import io.netty.channel.ChannelFuture;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 文件描述
 *
 * @program: SecurityControlPlatform
 * @author: zhenglx
 * @create: 2022/6/13
 */
@Service
@Slf4j
public class AlarmService {


    @Autowired
    TcpClient tcpClient;

    @Autowired
    TAlarmConfigMapper alarmConfigMapper;
    /**
     * 声光报警启动
     * @param no  报警编号
     * @return
     */
    public Result start(String no) {
        ChannelFuture future;
        try {
            String value = alarmConfigMapper.getParamValue(no,"启动");
             future = tcpClient.sendMsg(value);
//            Result.success(future.get());
        } catch (Exception e) {
            log.error("An error occurred in the transferTo : ", e);
            return new Result(500, "error ", e.getMessage());
        }
        return Result.success(future);
    }

    /**
     * 声光报警启动
     * @param no  报警编号
     * @return
     */
    public Result stop(String no) {
        try {
            String value = alarmConfigMapper.getParamValue(no,"停止");
            ChannelFuture future = tcpClient.sendMsg(value);
            Result.success(future.get());
        } catch (Exception e) {
            log.error("An error occurred in the transferTo : ", e);
            return new Result(500, "error ", e.getMessage());
        }
        return Result.success("。。。。");
    }
}
